# -*- coding: utf-8 -*-

"""
input: 一个顶点数组 items, 一个描述边的矩阵 matrix
output: 一个dot类型文本文件
"""

def draw_by_matrix(items, matrix, is_directed):
    size = len(items)

    graph_type = 'digraph' if is_directed else 'graph'
    edge_type = ' -> ' if is_directed else ' -- '

    txt = graph_type + ' matrix {'

    i = 0
    while i < size:
        txt += '\n' + 'n'+str(i)+'[label="'+str(items[i])+'"]'
        i += 1

    f = 0
    while f < size:
        t = f
        while t < size:
            if matrix[f][t] == 1:
                fstr = 'n' + str(f)
                tstr = 'n' + str(t)
                txt += '\n' + fstr + edge_type + tstr

            t += 1
        f += 1

    txt += '\n}'
    return txt

def draw_by_table(graph, is_directed):
    graph_type = 'digraph' if is_directed else 'graph'
    edge_type = ' -> ' if is_directed else ' -- '

    txt = graph_type + ' table {'
    for v in graph.keys():
        for w in graph[v]:
            txt += '\n' + 'V'+str(v) + edge_type + 'V'+str(w)
    txt += '\n}'
    return txt
